#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,y,m,d,day[100],i,x;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>y>>m>>d;
		day[i]=0;
		x=y%4==0&&y%100!=0||y%400==0;
		switch(m)
		{
			case 1:day[i]+=0;break;
			case 2:day[i]+=31;break;
			case 3:day[i]+=59+x;break;
			case 4:day[i]+=90+x;break;
			case 5:day[i]+=120+x;break;
			case 6:day[i]+=151+x;break;
			case 7:day[i]+=181+x;break;
			case 8:day[i]+=212+x;break;
			case 9:day[i]+=243+x;break;
			case 10:day[i]+=273+x;break;
			case 11:day[i]+=304+x;break;
			case 12:day[i]+=334+x;break;
		}
		cout<<day[i]+d<<endl;	
	}
    return 0;
}
